<?php
namespace BoxEdu\Widget;
class SubjectWidget extends \WidgetController
{
 


    /****订单列表***/
    public function order_list($where, $limit = "10")
    {
        $data = BoxModel("edu_subject_order")->get($where, $limit);
        $this->data = $data['list'];
        $this->show_page($data['pager']);
        $this->display();
    }

    /*****学员动态****/
    public function timeline($user_ids, $limit = 10, $type = "xuebazi", $mtype)
    {
        $where = 1;
        if ($user_ids) {
            $where .= " and user_id in ($user_ids)";
        }
        if ($type) {
            $where .= " and type='$type'";
        }
        if ($mtype == 1) {
            $where .= " and num >0";
        } elseif ($mtype == 2) {
            $where .= " and num <0";
        }
        $tpl = "Widget/timeline";
        if ($type == "money" || $type == "ask_num") {
            $tpl = "Widget/timeline_money";
        }
        $data = BoxModel("SystemLog")->get($where, 10);
        //dump(BoxModel("SystemLog"));
        // dump($data['list']);exit();
        $this->LogData = $data['list'];
        $this->type = $type;
        $this->pages = $data['pager'];
        // dump($this->pages);die;
        $this->display($tpl);
    }

    /*****班级动态****/
    public function class_timeline($class_ids, $limit = 10)
    {
        $where = "new_type=1";
        if ($class_ids) {
            $where .= " and pid in ($class_ids)";
        }
        $data = BoxModel("SnsTopic")->get("subject_class_new", $where, $limit);
        $this->TopicData = $data['list'];
        $this->display("Widget/class_timeline");

    }

    /*********访友*****/
    public function user_visit($user_ids, $limit = 10)
    {
        $where = 1;
        if ($user_ids) {
            $where .= " and user_id in ($user_ids)";
        }
        $data = BoxModel("EduUserVisit")->get($where, $limit);
        $this->WidgetData = $data['list'];
        $this->display("Widget/user_visit");
    }

    /***********练习******/
    public function subject_exercise($examid, $type = "all", $tpl_name = "Widget/subject_exercise")
    {
        $this->charactors = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
        $this->examid = $examid;
        $data = Logic("BoxEdu", "Exam")->load($examid);
        $this->type = $type;
        $GLOBALS['marking'] = $data['marking']['right_answer'];
        $examquestions = $data['examsetting']['questype'];
        $this->examquestions = $examquestions;
        //dump($examquestions);
        $this->display($tpl_name);
    }

    /******显示选择题目**/
    public function show_questions($data, $key2)
    {
        $this->count_key = $key2;
        $this->type = I('type', "all");
        $data['user_answer'] = $GLOBALS['marking'][$data['questionid']];
        $type = $data['user_answer']['type'] ? $data['user_answer']['type'] : $this->type;
        $data['marking'] = $type . "_questions";
        //dump($data);
        if ($data['user_answer']['type'] == "right") {
            //dump($data['user_answer']);
            foreach ($data['questionanswer'] as $k => $one) {
                if ($one['choose'] == 1) {
                    $data['questionanswer'][$k]['checked'] = "checked";
                }
            }
        }
        $this->questions_data = $data;
        if (ACTION_NAME == "moni_jiexi") {
            $this->display("Widget/show_questions_jiexi");
        } else {
            $this->display("Widget/show_questions");
        }
    }

    /******显示分录题**/
    public function show_questions_5($data)
    {
        $data['user_answer'] = $GLOBALS['marking'][$data['questionid']];
        $this->type = I('type', "all");
        $type = $data['user_answer']['type'] ? $data['user_answer']['type'] : $this->type;
        $data['marking'] = $type . "_questions";
        $this->type = I('type');
        $this->questions_data_5 = $data;
        if (ACTION_NAME == "moni_jiexi") {
            $this->display("Widget/show_questions_5_jiexi");
        } else {
            $this->display("Widget/show_questions_5");
        }
    }

    /*******子题***/
    public function  sub_questions($pid)
    {
        $data = BoxModel("edu_questions")->get("questionparent='$pid' and questionstatus=1");
        $this->sub_questions_list = $data['list'];
        //dump($data);
        $this->display("Widget/sub_questions");
    }

    /***********章节******/
    public function subject_section($subjectid, $type = "section")
    {
        $this->type = $type;
        $this->data = BoxModel("EduSubject")->load($subjectid);
        $data = BoxModel("EduSubject")->get_section_by_subjectid($subjectid);
        $has_buy = Logic("BoxEdu", "Subject")->has_buy($subjectid);
        foreach ($data as $k => $one) {
            $sectionid = $one['sectionid'];
            $knows = BoxModel("EduSubject")->get_knows($sectionid);
            foreach ($knows as $k2 => $one2) {
                if ($has_buy['error'] == 2) $knows[$k2]['knows'] = $one2['knows'] . "（需正式开通课程）";
            }
            $data[$k]['knows'] = $knows;
        }

        $this->list = $data;
        // $this->list=$data;
        $this->display("Widget/subject_section");
    }

    /*********笔记********/
    public function subject_notes($knowsid, $user_id)
    {
        $this->data = BoxModel("edu_subject_notes")->where("user_id='$user_id' and knowsid='$knowsid'")->find();
        $this->notes = $this->data['notes'];
        if (!$this->notes) {
            $data = BoxModel("edu_knows")->load($knowsid);
            $this->notes = strip_tags($data['pt_note']);
        }

        $this->display("Widget/subject_notes");
    }

    /*********问题列表********/
    public function ask_list($where, $limit = 10)
    {
        $data = Logic("BoxEdu", "Ask")->get($where, $limit, "S.updatetime desc");
        $ndata = $data['list'];
        foreach ($ndata as $key => $value) {
            $ndatas = BoxModel("SnsComment")->get("ask", "pid='" . $value['topic_id'] . "'", 5, "comment_id"); //回答列表
            $ndata[$key]['answers'] = $ndatas['list'];
        }
        $this->total = count($ndata);
        $this->data = $ndata;
        // dump($where);die;
        $this->show_page($data['pager']);
        $this->display("Widget/ask_list");
    }

    /*********试卷列表********/
    public function exams_list($where, $limit)
    {
        $this->list = Logic("BoxEdu", "Exam")->get($where);
        $this->display("Widget/exams_list");
    }

    /********我的回复*****/
    public function ask_answer($where, $limit)
    {
        $comment_data = BoxModel("SnsComment")->get("ask", $where, 5, "comment_id"); //评论列表
        $this->comment_data = $comment_data['list'];
        // dump($comment_data['list']);exit();
        $this->show_page($comment_data['pager']);
        $this->display("Widget/ask_answer");
    }


}